-- addition_base_damage
-- create by wangy
-- 道具：对玩家造成N点伤害，概率额外造成玩家基础属性%的伤害

return {
    apply = function(source, target, classId, value)
        -- 传入攻击者信息
        local assailantInfo = {
            ["property_id"] = classId,
        };

        -- 道具伤害加成
        local damage = value[1];

        -- 道具伤害加成
        if PropertyM.query(classId, "target") ~= PROPERTY_SELF then
            local prop = PropM.combine(source, "property_damage", 1);
            damage = PropM.apply(prop, damage);
        end

        -- 概率额外基础属性伤害
        if DungeonM.getRandSeed("addition_base_damage") % 1000 <= value[2] then
            local attrib = value[3];
            local addDamage;

            -- 判断boss是否1减半、2翻倍
            if target:isBoss() and value[5] == 1 then
                addDamage = math.modf(InterfaceM.calcBaseAttrib(ME.user, attrib) * value[4] / 2000);
            elseif target:isBoss() and value[5] == 2 then
                addDamage = math.modf(InterfaceM.calcBaseAttrib(ME.user, attrib) * value[4] / 500);
            else
                addDamage = math.modf(InterfaceM.calcBaseAttrib(ME.user, attrib) * value[4] / 1000);
            end

            -- 保底
            addDamage = math.max(addDamage, 1);
            damage    = damage + addDamage;
        end

        -- 修正伤害值
        damage = PropertyM.fixPropertyDamage(source, target, classId, damage);

        if ItemM.query(classId, "apply") == "damage_and_drop" then
            -- 会掉落道具
            CombatM.doDamage(source, target, damage, 0, true, { assailantInfo = assailantInfo, });
        else
            CombatM.doDamage(source, target, damage, 0, false, { assailantInfo = assailantInfo, });
        end

        -- 抛出使用道具攻击事件
        EventMgr.fire(event.PROPERTY_ATTACK, { ["classId"] = classId, ["target"] = target, ["source"] = source});
    end,
};
